//
//  RBCategoryBaseListController.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/12.
//

#import "RBCategoryBaseListController.h"
#import "RBCategoryListContainerViewController.h"

@interface RBCategoryBaseListController ()
@property(strong,nonatomic)UIView *bottomLineView;
@end

@implementation RBCategoryBaseListController
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navHeight = 0;
    
    [self.view addSubview:self.categoryView];
    [self.view addSubview:self.listContainerView];
    
    UIView *bottomLineView = [[UIView alloc]init];
    bottomLineView.backgroundColor = RBColor(237, 237, 237);
    [self.categoryView addSubview:bottomLineView];
    [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    self.bottomLineView = bottomLineView;
}
- (void)setIsHidBottomLineView:(BOOL)isHidBottomLineView{
    _isHidBottomLineView = isHidBottomLineView;
    self.bottomLineView.hidden = isHidBottomLineView;
}
- (JXCategoryBaseView *)preferredCategoryView {
    return [[JXCategoryBaseView alloc] init];
}
- (CGFloat)preferredCategoryViewHeight {
    return RBScaleWidth(44);
}
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}
#pragma mark - JXCategoryListContainerViewDelegate
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}
-(id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    RBCategoryListContainerViewController *categoryListVc = [[RBCategoryListContainerViewController alloc] init];
    return categoryListVc;
}
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.categoryView.frame = CGRectMake(0, self.navHeight, RBScreenWidth, [self preferredCategoryViewHeight]);
    self.listContainerView.frame = CGRectMake(0, [self preferredCategoryViewHeight]+self.navHeight, RBScreenWidth, RBScreenHeight-[self preferredCategoryViewHeight]-self.navHeight);
}

- (JXCategoryBaseView *)categoryView {
    if (!_categoryView) {
        _categoryView = [self preferredCategoryView];
        _categoryView.delegate = self;
        _categoryView.listContainer = self.listContainerView;
    }
    return _categoryView;
}
- (JXCategoryListContainerView *)listContainerView {
    if (!_listContainerView) {
        _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    }
    return _listContainerView;
}


@end
